package main

import "encoding/json"

type Book struct  {
	Title string
	Author string
	published bool
	price float64
}



func main() {
	scala := Book{
		"scala程序设计",
		"张三",
		true,
		108.5,
	}

	b,err := json.Marshal(scala)
	if err != nil {
		println("err book json")
	}
	println(string(b))

	var book Book
	err = json.Unmarshal(b,&book)
	if err != nil {
		println("err unmarshal")
	}
	println(book.Title,book.price,book.published)

	var r interface{}
	err = json.Unmarshal(b,&r)
	if err != nil {
		println("err unmarshal")
	}
	scalabook,ok :=r.(map[string]interface{})
	if ok {
		for k,v :=range scalabook  {
			switch v2 :=v.(type) {
			case string:
				println(k,"is string ",v2)
			case bool:
				println(k,"is bool ",v2)
			default:
				println("unknow ")
			}
		}
	}

}
